<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
set_html('title','商户列表');
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params1=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array('keyword'=>'','page'=>1);	
	//获取最近50家店
	if($_RQ['lat'] || $_RQ['lng']){
		$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
		$this->session('lat_lng',$lat_lng);
	}
	$lat_lng=$this->session('lat_lng');
	$orderby='id asc';
	if($_RQ['orderby']=='time'){
		$orderby='jointime desc';		
	}
	$cateid=intval($_RQ['cateid']);
	if($cateid){
		$params['cateid OR']='cateid='.$cateid.' OR cateid2 like \'%;'.$cateid.';%\' ';
		$return['params']['cateid']=$cateid;
	}
	if(trim($_RQ['keyword'])){
		$params['merchname like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	$pindex = max(1, 1);
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,10000),//获取所有
		'fields'=>array('id','merchname','address','mobile','lat_lng','logo','cateid'),
		'key'=>'id',
		'orderby'=>$orderby,
		'orderbykey'=>$orderbykey,
	);
	if($_RQ['orderby']=='500'){
			$limitjuli=500;
	}
	if($_RQ['orderby']=='1000'){
			$limitjuli=1000;
	}
	if($_RQ['orderby']=='2000'){
			$limitjuli=2000;
	}
	if($_RQ['orderby']=='5000'){
			$limitjuli=5000;
	}
	if($_RQ['orderby']=='more'){
			$limitjuli=0;
	}
	$merchs=model('jy_merch/model')->getmerch($parameter,$_RQ['num'],$lat_lng,intval($_RQ['page']),$limitjuli);
	foreach($merchs as &$v){
		$v['logo']=tomedia($v['logo']);
		$v['onlinetime']=json_decode($v['onlinetime'],true);
		$v['catename']=pdo_getcolumn('jy_merch_category',array('id'=>$v['cateid']),'catename');		
	}
	$return['list']=$merchs;
	$return['cate']=pdo_getslice('jy_merch_category',$params1,array($pindex,10),$total,$fields,'','id desc');
	exi($return);	
}

?>